sortlistmodel: Make sort stable again
authorBenjamin Otte <otte@redhat.com>
Tue, 21 Jul 2020 02:06:13 +0000 (04:06 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 22 Jul 2020 12:30:49 +0000 (14:30 +0200)
Previously, the sort was not stable when items were added/removed while
sorting or the sort algorithm was changed.

Now the sort looks at the item position (via the key's location in the
keys array) to make sure each comparison stays stable with respect to
this position.

gtk/gtksortlistmodel.c

index 37dcd6f18e9578e5c4a83019a954d94f127e9877..5fa310532324dab6d29de32c5c5c0cc5a3b1fbb8 100644 (file)
@@ -255,7 +255,11 @@ sort_func (gconstpointer a,
   gpointer *sb = (gpointer *) b;
   int result;
 
-  return gtk_sort_keys_compare (data, *sa, *sb);
+  result = gtk_sort_keys_compare (data, *sa, *sb);
+  if (result)
+    return result;
+
+  return *sa < *sb ? -1 : 1;
 }
 
 static gboolean